package com.itheima.controller;

import com.alibaba.fastjson.JSON;

import com.itheima.pojo.ExceptionLogVO;
import com.itheima.service.ExceptionLogService;
import com.itheima.pojo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/log")
public class ExceptionLogController {

    @Autowired
    private ExceptionLogService exceptionLogService;

    @PostMapping("/getExceptionList")
    public Map<String, Object> getExceptionList(@RequestBody ExceptionLogVO exceptionLogVO){

        /*
        * currentPage: 1
          operation: ""
           userName:
           startTime""*/

        PageResult exceptionList = exceptionLogService.getExceptionList(exceptionLogVO);
        List rows = exceptionList.getRows();
        Long total = exceptionList.getTotal();

        Map<String,Object> result= new HashMap<>();


        Map<String,Object> recordsMap = new HashMap<>();

        recordsMap.put("records",rows);
        recordsMap.put("total",total);
        recordsMap.put("size",10);
        recordsMap.put("current",exceptionLogVO.getCurrentPage());

        recordsMap.put("orders",null);
        recordsMap.put("optimizeCountSql",true);
        recordsMap.put("isSearchCount",true);

        result.put("code","success");
        result.put("data",recordsMap);
        //返回结果
        return result;
    }
}
